package com.example.springboot.utils.file;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

/**
 * 
 * desc:生成数据库xml参数
 * 
 * @author wangsh
 * @date Jan 17, 2018 10:47:36 AM
 */
public class CallProxmlUtils {

	public static String createXml(String sb1, String dbName) {
		StringBuilder sb = new StringBuilder();
		sb.append("<root>");
		sb.append("<DataList>");
		sb.append(sb1);
		sb.append("</DataList>");
		sb.append("<row DatabaseName = \"" + dbName + "\"  />");
		sb.append("</root>");
		sb.append("");
		return sb.toString();
	}
	
	public static String createSingleXml(String sb1) {
		StringBuilder sb = new StringBuilder();
		sb.append("<root>");
		sb.append(sb1);
		sb.append("</root>");
		sb.append("");
		return sb.toString();
	}

	/**
	 * 根据数据创建xml数据串
	 * 
	 * @param map
	 * @return
	 */
	public static String createValStr(HashMap<String, Object> map) {
		// "	<row UnitID = \"-987654321112\" UnitCode = \"Test123***\" UnitName = \"Test123\" AreaCode = \"440401\" PoliceStationCode = \"Test123\" Status = \"12\" GuildID = \"12\" UnitTypeCode = \"Test123\" CreateTime = \"2015-04-07 11:55:51\" UpdateTime = \"2015-04-07 11:55:51\" ConnTime = \"2015-04-07 11:55:51\" Memo = \"Test123\" Lon = \"113.583700\" Lat = \"22.255030\" Address = \"Test123\" ManufacturerCode = \"Test123\" Integration = \"12\" IsDeleted = \"12\" DeleteTime = \"2015-04-07 11:55:51\" BusinessStatus = \"12\" OpenTime = \"08:12\" CloseTime = \"23:00\" CorporateName = \"Test123\" CorporateCertCode = \"Test123\" CorporateCertType = \"1\" CorporateMobile = \"Test123\" OldUnitCode = \"Test123\" />"
		// +
		if (map == null || map.isEmpty())
			return "";
		StringBuilder vals = new StringBuilder("<row ");
		Set<Entry<String, Object>> sets = map.entrySet();
		Iterator<Entry<String, Object>> it = sets.iterator();
		while (it.hasNext()) {
			Entry<String, Object> e = it.next();
			vals.append(e.getKey());
			vals.append("=\"" + e.getValue() + "\" ");
		}
		vals.append(" />");
		return vals.toString();
	}
}
